//################################################################################################################################//
//##                                                                                                                            ##//
//## This page is designed and developed to implement "Doctor Recommendation  "(My Find A Doc HealthCare-IV)                    ##//
//##                                                                                                                            ##//
//## Author   : Akash Saxena                                                                                                    ##//
//## Dated    : 18 Sep '07                                                                                                      ##//
//##                                                                                                                            ##//
//################################################################################################################################//
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;

public partial class Doctor_Recommend : System.Web.UI.Page
{
    //Create object of Manager and Doctor Class.
    Manager objManager = new Manager(true,"ConnectionString");
    Doctor objDoctor = new Doctor();

    int iUserid = 0;
    string sLoginname = "";
    string sUserEmail = "";
    int iDoctorId = 0;
    string strMsg = "";

    #region Events 
    
    /// <summary>
    /// Page Load
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <Author>Akash Saxena</Author>
    /// <Date>26 Sep 2007</Date>
    protected void Page_Load(object sender, EventArgs e)
    {

        localFunction lfunction = new localFunction();

        //Check User Login
        lfunction.checkPatientLogin(true);

        //if proper querystring is found
        if (Request.QueryString["Id"] != null && Request.QueryString["Id"].ToString().Trim() != "")
        {
            if (Manager.IsNumeric(Request.QueryString["Id"].ToString()))
                iDoctorId = Convert.ToInt32(Request.QueryString["Id"]);
        }
        else
        { iDoctorId = 0; }


        //if some user is available in the session
        if (Session["LoginName"] != null && Session["LoginName"].ToString().Trim() != "")
            sLoginname = Session["LoginName"].ToString();

        if (Session["userID"] != null && Session["userID"].ToString().Trim() != "")
            iUserid = Convert.ToInt32(Session["userID"]);
        else
            iUserid = 0;


        if (Session["useremail"] != null && Session["useremail"].ToString().Trim() != "")
            sUserEmail = Session["useremail"].ToString();

    }
 
    protected void btnRecommend_Click(object sender, EventArgs e)
    {
        localFunction lfunctionobj = new localFunction();
        string strDoctorName = "";

        SqlDataReader objDataReader = null;
        objDataReader = objManager.ExecuteQuery("select (fname +' ' + MName + ' '+ LName)as Name from tbl_doctors where id=" + iDoctorId.ToString());
        if (objDataReader.HasRows)
        {
            objDataReader.Read();
            strDoctorName = objDataReader["Name"].ToString();
        }

        //Retrieve Doctor View Profile URL.
        if (txtRecommend1.Text == "" && txtRecommend2.Text == "" && txtRecommend3.Text == "" && txtRecommend4.Text == "" && txtRecommend5.Text == "")
        {
            lblMsg.Text = "Enter at least one Email Id.";
            lblMsg.ForeColor = System.Drawing.Color.Red;
            lblMsg.Font.Bold = true;
        }
        else
        {
            string EmailIds = "";
            if (txtRecommend1.Text.Trim().Length > 0)
            {
                EmailIds = txtRecommend1.Text.Trim();
            }

            if (txtRecommend2.Text.Trim().Length > 0)
            {
                if (EmailIds.Length == 0)
                    EmailIds = txtRecommend2.Text.Trim();
                else
                    EmailIds = EmailIds + ";" + txtRecommend2.Text.Trim();
            }
            if (txtRecommend3.Text.Trim().Length > 0)
            {
                if (EmailIds.Length == 0)
                    EmailIds = txtRecommend3.Text.Trim();
                else
                    EmailIds = EmailIds + ";" + txtRecommend3.Text.Trim();
            }
            if (txtRecommend4.Text.Trim().Length > 0)
            {
                if (EmailIds.Length == 0)
                    EmailIds = txtRecommend4.Text.Trim();
                else
                    EmailIds = EmailIds + ";" + txtRecommend4.Text.Trim();
            }
            if (txtRecommend5.Text.Trim().Length > 0)
            {
                if (EmailIds.Length == 0)
                    EmailIds = txtRecommend5.Text.Trim();
                else
                    EmailIds = EmailIds + ";" + txtRecommend5.Text.Trim();
            }

            if (Session["strHttp"] != null)
            {
                //Comented for implement new URL Formate at 17/07/08 by Ranjeet 
                //strMsg = sLoginname + " " + "has recommended Dr." + strDoctorName + " " + "to you. " + " " + "His/Her profile can be viewed from the following URL :<a href='" + Session["strHttp"].ToString() + "/Doctor/DoctorsDetails.aspx?id=" + iDoctorId + "'> Click Here</a>";
                string docdetailsURL = "";
                docdetailsURL = HttpContext.Current.Session["strHttp"] + "doctors/" + lfunctionobj.GetURLFormatById(iDoctorId, "DOCTOR") + "/" + iDoctorId.ToString() + "-" + strDoctorName + ".aspx";
                strMsg = sLoginname + " " + "has recommended Dr." + strDoctorName + " " + "to you. " + " " + "His/Her profile can be viewed from the following URL :<a href='" + docdetailsURL + "'> Click Here</a>";

            }
            else
            {
                //Comented for implement new URL Formate at 17/07/08 by Ranjeet 
                //strMsg = sLoginname + " " + "has recommended Dr." + strDoctorName + " " + "to you. " + " " + "His/Her profile can be viewed from the following URL :<a href='http://www.findadoc.com/Doctor/DoctorsDetails.aspx?id=" + iDoctorId + "'> Click Here</a>";
                string docdetailsURL = "";
                docdetailsURL =lfunctionobj.GetURLFormatById(iDoctorId, "DOCTOR") + "/" + iDoctorId.ToString() + "-" + strDoctorName + ".aspx";
                strMsg = sLoginname + " " + "has recommended Dr." + strDoctorName + " " + "to you. " + " " + "His/Her profile can be viewed from the following URL :<a href='http://www.findadoc.com/Doctors/'" + docdetailsURL + "''> Click Here</a>";
            }

            objManager.sendMail(strMsg, EmailIds, sLoginname, "Recommend to a Doctor", sUserEmail, "");
            lblMsg.Text = "Message has sent successfully";
            

        }
        objDataReader.Close();
        objDataReader.Dispose();
    }

    #endregion
}
